package com.baturu.vin.honda.dal.dao;

import com.baturu.vin.honda.dal.entity.*;
import com.baturu.vin.honda.dto.HondaPartsDescDTO;
import com.baturu.vin.honda.dto.HondaPartsFeaturesDTO;
import com.baturu.vin.honda.dto.HondaPartsInfoDTO;
import com.baturu.vin.honda.dto.HondaRepPartsDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * 本田配件DAO
 *
 * @author jiangxinlei
 */
public interface HondaPartDAO {

    @Select({"<script>",
            "SELECT hpartplblk, npl, nplblk, nplpartref, nplpartrefseq, npartgenu, csernumcont,nserepcstrt,nserepcend,xordergun ",
            " from honda_parts_info",
            "where npl = #{npl}",
            "and disk=#{disk}",
            "and npartgenu in",
            "<foreach item='partsCode' index='index' collection='partsCodes' open='(' separator=',' close=')'>",
            "#{partsCode}",
            "</foreach>",
            "and nplblk in ",
            "<foreach item='nplblk' index='index' collection='nplblks' open='(' separator=',' close=')'>",
            "#{nplblk}",
            "</foreach>",
            "</script>"})
    Set<HondaPartsInfoDTO> findPartsInfo(@Param("partsCodes") Collection<String> partsCodes, @Param("npl") String npl, @Param("disk") String disk, @Param("nplblks") Collection<String> nplblks);

 @Select({"<script>",
            "SELECT hpartplblk, npl, nplblk, nplpartref, nplpartrefseq, npartgenu, csernumcont,nserepcstrt,nserepcend,xordergun ",
            " from honda_parts_info_v2",
            "where npl = #{npl}",
            "and disk=#{disk}",
            "and partsId in",
            "<foreach item='partsCode' index='index' collection='partsCodes' open='(' separator=',' close=')'>",
            "#{partsCode}",
            "</foreach>",
            "and nplblk in ",
            "<foreach item='nplblk' index='index' collection='nplblks' open='(' separator=',' close=')'>",
            "#{nplblk}",
            "</foreach>",
            "</script>"})
    Set<HondaPartsInfoDTO> findPartsInfoByPartsId(@Param("partsCodes") Collection<String> partsCodes, @Param("npl") String npl, @Param("disk") String disk, @Param("nplblks") Collection<String> nplblks);

    @Select({"<script>",
            "SELECT DISTINCT hpartplblk FROM honda_parts_hmodtyp",
            "WHERE HPARTPLBLK IN ",
            "<foreach item='partblk' index='index' collection='partBlks' open='(' separator=',' close=')'>",
            "#{partblk}",
            "</foreach>",
            "AND HMODTYP IN",
            "<foreach item='hmodtyp' index='index' collection='hmodTyps' open='(' separator=',' close=')'>",
            "#{hmodtyp}",
            "</foreach>",
            "and disk = #{disk}",
            "</script>"})
    Set<Integer> findPartsByHmodTyps(@Param("partBlks") Set<Integer> partBlks, @Param("hmodTyps") Set<Integer> hmodTyps, @Param("disk") String disk);

    @Select({"<script>",
            "SELECT DISTINCT hpartplblk FROM honda_parts_hmodtyp",
            "WHERE HPARTPLBLK IN ",
            "<foreach item='partblk' index='index' collection='partBlks' open='(' separator=',' close=')'>",
            "#{partblk}",
            "</foreach>",
            "and disk = #{disk}",
            "</script>"})
    Set<Integer> findPartsRelation(@Param("partBlks") Set<Integer> partBlks, @Param("disk") String disk);

    @Select({"<script>",
            "SELECT hpartplblk, npl, nplblk, nplpartref, nplpartrefseq, npartgenu, csernumcont,nserepcstrt, nserepcend, cengnfrm, xordergun from honda_parts_info",
            "where npartgenu in",
            "<foreach item='partsCode' index='index' collection='partsCodes' open='(' separator=',' close=')'>",
            "#{partsCode}",
            "</foreach>",
            "</script>"})
    Set<HondaPartsInfoDTO> findPartsInfoByCode(@Param("partsCodes") Set<String> partsCodes);


    @Select({"<script>",
            "SELECT hpartplblk, npl, nplblk, nplpartref, nplpartrefseq, npartgenu, csernumcont,nserepcstrt, nserepcend, cengnfrm, xordergun from honda_parts_info",
            "where npartgenu in",
            "<foreach item='partsCode' index='index' collection='partsCodes' open='(' separator=',' close=')'>",
            "#{partsCode}",
            "</foreach>",
            "AND npl = #{npl}",
            "and disk = #{disk}",
            "</script>"})
    Set<HondaPartsInfoDTO> findPartsInfoByCodeAndVin(@Param("partsCodes") Collection<String> partsCodes, @Param("npl") String npl, @Param("disk") String disk );


    @Select({"<script>SELECT DISTINCT a.NPARTGENU, b.colorRemark FROM honda_parts_color as a JOIN honda_color_description as b on a.CHESCOL_PART = b.CHESCOL",
            "where a.NPARTGENU in ",
            "<foreach item = 'partsCode' index='index' collection='partsCodes' open='(' separator=',' close=')'>",
            "#{partsCode}",
            "</foreach>",
            "and a.disk = #{disk}",
            "</script>"})
    List<HondaPartsInfoDTO> findPartsColor(@Param("partsCodes") Collection<String> partsCodes, @Param("disk") String disk);

    @Select({"<script>select distinct partsCode, repPartsCode from honda_replace_code where disk=#{disk} and npl=#{npl} and partsCode in ",
            "<foreach item='partsCode' index='index' collection='partsCodes' open='(' separator=',' close=')'>",
            "#{partsCode}",
            "</foreach>",
            "and hmodtyp in",
            "<foreach item='hmodtyp' index='index' collection='hmodtyps' open='(' separator=',' close=')'>",
            "#{hmodtyp}",
            "</foreach>",
            "</script>"})
    List<HondaRepPartsDTO> findRepPartsInfos(@Param("disk") String disk, @Param("npl") String npl, @Param("partsCodes") Set<String> partsCodes, @Param("hmodtyps") Set<Integer> hmodtyps);

    @Select({"<script>",
            "SELECT distinct hpartplblk, npl, nplblk, nplpartref, nplpartrefseq, npartgenu, csernumcont,nserepcstrt, nserepcend, cengnfrm, xordergun from honda_parts_info",
            "where npl = #{npl}",
            "and disk = #{disk}",
            "and nplblk in ",
            "<foreach item='nplblk' index='index' collection='nplblks' open='(' separator=',' close=')'>",
            "#{nplblk}",
            "</foreach>",
            "</script>"})
    List<HondaPartsInfoDTO> findPartsInfoByNplAndNplBlk(@Param("npl") String npl, @Param("disk") String disk, @Param("nplblks") Set<String> nplblks);

    @Select("<script>" +
            "SELECT NPARTGENU partsCode,XPARTEXT epcPartsName,disk " +
            "FROM honda_parts_desc " +
            "WHERE NPARTGENU IN " +
            "<foreach item='item' index='index' collection='partsCode' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<HondaPartsDescDTO> findPartsDesc(@Param("partsCode") Set<String> partsCode);

    @Select("<script>" +
            "SELECT partsCode,epcPartsNameCN " +
            "FROM honda_parts_desc_cn " +
            "WHERE partsCode IN " +
            "<foreach item='item' index='index' collection='partsCode' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<HondaPartsDescDTO> findPartsDescCN(@Param("partsCode") Set<String> partsCode);

    @Select("<script>" +
            "SELECT partsCode,features,quality " +
            "FROM honda_parts_features " +
            "WHERE partsCode IN " +
            "<foreach item='item' index='index' collection='partsCode' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<HondaPartsFeaturesDTO> queryPartsFeatures(@Param("partsCode") Collection<String> partsCode);


    @Select({"<script>" ,
            "SELECT stamp,btr_parts_name as btrPartsName from honda_special_name where btr_parts_name IN " ,
            "<foreach item='item' index='index' collection='names' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"})
    List<HondaSpecialNameEntity> querySpecialName(@Param("names") Set<String> names);


    @Select({"<script>" ,
            "SELECT DISTINCT" ,
            "npartgenu,",
            "xhecol1,",
            "disk,",
            "chescol,",
            "npl",
            "FROM honda_color_info ",
            "where",
            "npartgenu in",
            "<foreach item='item' index='index' collection='partsCodes' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "and disk=#{disk}",
            "</script>"})
    List<HondaPartsColorInfoEntity> queryColorInfo(@Param("partsCodes")Set<String> partsCode,@Param("disk")String disk);



    @Select({"<script>",
            "SELECT",
            "hpartplblk,",
            "hmodtyp",
            "FROM honda_pbpmtt",
            "WHERE",
            "disk=#{disk}",
            "AND hpartplblk IN",
            "<foreach item='item' index='index' collection='hpartplblks' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"})
    List<HondaHpartAndHmodEntity> queryAllhmodtyp(@Param("disk")String disk, @Param("hpartplblks")Set<Integer> hpartplblks);



    @Select({"<script>",
            "SELECT",
            "hmodtyp,",
            "npl,",
            "nplblk",
            "FROM honda_pblmtt",
            "WHERE",
            "disk=#{disk}",
            "AND nplblk IN",
            "<foreach item='item' index='index' collection='partsInfos' open='(' separator=',' close=')'>",
            "#{item.nplblk}",
            "</foreach>",
            "AND hmodtyp IN",
            "<foreach item='item' index='index' collection='hmodtyps' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "AND npl IN",
            "<foreach item='item' index='index' collection='partsInfos' open='(' separator=',' close=')'>",
            "#{item.npl}",
            "</foreach>",
            "</script>"})
    List<HondaConditionCEntity> queryConditionC(@Param("disk")String disk, @Param("partsInfos")List<HondaPartsInfoDTO> nplblks, @Param("hmodtyps")Set<Integer> hmodtyps);



}
